import request from '@/utils/request'

// 查询报告文件信息列表
export function listReport(query) {
  return request({
    url: '/analysis/report/list',
    method: 'get',
    params: query
  })
}

// 查询报告文件信息详细
export function getReport(reportId) {
  return request({
    url: '/analysis/report/' + reportId,
    method: 'get'
  })
}

// 新增报告文件信息
export function addReport(data) {
  return request({
    url: '/analysis/report',
    method: 'post',
    data: data
  })
}

// 修改报告文件信息
export function updateReport(data) {
  return request({
    url: '/analysis/report',
    method: 'put',
    data: data
  })
}

// 删除报告文件信息
export function delReport(reportId) {
  return request({
    url: '/analysis/report/' + reportId,
    method: 'delete'
  })
}
//获取多赢的策略
export function selectStrategyDetail(brandId, checkId) {
  return request({
    url: '/strategy/method/checkType',
    method: 'get',
    params: {
      brandId: brandId,
      checkId: checkId
    }
  })
}


// 上传多个pdf文件
/**
 * 上传文件接口
 * @param {File[]} files - 要上传的文件数组
 * @param {number} [brandId] - 可选，品牌ID
 * @param {number} [reportId] - 可选，报告ID
 * @param {number} [checkId] - 可选，检查ID
 * @returns {Promise} 请求结果
 */
export function uploadFiles(files, brandId, reportId, checkId) {
  // 创建FormData对象用于文件上传
  const formData = new FormData();

  // 添加文件到FormData
  for (let i = 0; i < files.length; i++) {
    formData.append('files', files[i]);
  }
  // 添加可选参数
  if (brandId !== undefined && brandId !== null) {
    formData.append('brandId', brandId);
  }
  if (reportId !== undefined && reportId !== null) {
    formData.append('reportId', reportId);
  }
  if (checkId !== undefined && checkId !== null) {
    formData.append('checkId', checkId);
  }

  return request({
    url: '/common/uploads',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type':'multipart/form-data'
    }
  });
}
// 获取pdf文件列表
export function selectPdfUrlList(reportId) {
  return request({
    url: '/analysis/url/pdfUrl/List' + '?reportId=' + reportId,
    method: 'get',
  })
}

export function deletePdfUrl(fileId) {
  return request({
    url: '/analysis/url/deleted/pdf/fileId',
    method: 'get',
    params: {fileId}
  })
}

export function saveStrategy(sVoList, brandId, checkId) {
  return request({
    url: '/strategy/method/save',
    method: 'post',
    data: sVoList,
    params: {brandId,checkId}
  })
}


// 获取执行策略后的数据信息
export function selectFileData(reportFileId,fileId) {
  return request({
    url: '/analysis/data/getReportData',
    method: 'get',
    params: {reportFileId,fileId}
  })
}

// 运作策略
export function runStrategyReport( brandId, checkId,reportFileId,fileId) {
  return request({
    url: '/strategy/method//run/strategy',
    method: 'get',
    params: {brandId,checkId,reportFileId,fileId}
  })
}

